package com.example.wiki.resp;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 通用返回结果类
 *
 * @param <T> 数据类型
 */
@ApiModel(value = "通用返回结果")
public class CommonResp<T> {

    /**
     * 业务上的成功或失败
     */
    private boolean success = true;

    /**
     * 返回信息
     */
    @ApiModelProperty(value = "返回消息", example = "操作成功")
    @JSONField(name = "message")
    private String message;

    /**
     * 返回泛型数据，自定义类型
     */
    @ApiModelProperty(value = "返回内容")
    @JSONField(name = "content")
    private T content;

    @ApiModelProperty(value = "返回码", example = "200")
    @JSONField(name = "status")
    private  Number status= 200 ;

    // 无参构造函数，可能需要在序列化库中使用
    public CommonResp() {}

    /**
     * 成功返回的构造函数
     *
     * @param content 返回的数据
     */
    public CommonResp(T content) {
        this.status = 200;
        this.message = "操作成功";
        this.content = content;
    }
    /**
     * 带状态码和消息的构造函数
     *
     * @param status 状态码
     * @param message 消息
     * @param content 返回的数据
     */
    public CommonResp(Integer status, String message, T content) {
        this.status = status;
        this.message = message;
        this.content = content;
    }

    public Number getStatus() {
        return status;
    }

    public void setStatus(Number status) {
        this.status = status;
    }

    public boolean getSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "CommonResp{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", content=" + content +
                ", status=" + status +
                '}';
    }
}